/**
 *
 * Created by jinglupeng on 2/12/16.
 */

var Timer = module.exports = React.createClass({
    getInitialState: function () {
        console.log('getInitialState');
        return {
            secondsElapsed: 0
        };
    },
    tick: function () {
        console.log('tick');
        this.setState({
            secondsElapsed: this.state.secondsElapsed + 1
        });
    },
    componentDidMount: function () {
        console.log('componentDidMount');
        this.interval = setInterval(this.tick, 1000);
    },
    componentWillUnmount: function () {
        console.log('componentWillUnmount');
        clearInterval(this.interval);
    },
    render: function () {
        return (
            <div>Seconds Elapsed: {this.state.secondsElapsed}</div>
        );
    }
});

